package appapi.controller.oider;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
@RequestMapping("/api")
public class TokenController {
    @GetMapping("/token")
    public ResponseEntity<String> getToken() {
        String url = "https://open.ys7.com/api/lapp/token/get";
        String appKey = "YOUR_APP_KEY";
        String appSecret = "YOUR_APP_SECRET";
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        String requestBody = "{\"appKey\":\"" + appKey + "\",\"appSecret\":\"" + appSecret + "\"}";
        HttpEntity<String> entity = new HttpEntity<>(requestBody, headers);
        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
//        // Parse the response and extract the required values
//        String token = ""; // Extract the token value from the response
        return response;
    }
}